package com.xmall.auth.controller;

import com.xmall.aspect.OperateRecord;
import com.xmall.auth.service.ISysAccountService;
import com.xmall.define.base.Result;
import com.xmall.define.dict.OperateTypeEnum;
import com.xmall.define.dto.auth.AccountDto;
import com.xmall.define.dto.auth.AccountUpdateRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 账号
 */
@RequestMapping("/service/auth/sys/account")
@RestController
public class SysAccountController {

    @Resource
    private ISysAccountService sysAccountService;

    /**
     * 指定用户列表账号信息
     */
    @PostMapping("/listByUserIds")
    public Result<List<AccountDto>> listByUserIds(@RequestBody List<Long> userIds){
        List<AccountDto> result = sysAccountService.listByUserIds(userIds);
        return null != result ? Result.success(result) : Result.error();
    }

    /**
     * 账号是否存在
     */
    @GetMapping("/exists/{account}")
    public Result<Boolean> exists(@PathVariable("account") String account){
        Boolean result = sysAccountService.exists(account);
        return Result.success(result);
    }

    /**
     * 保存
     */
    @OperateRecord(type = OperateTypeEnum.ADD)
    @PostMapping("/save")
    public Result saveEntity(@Validated @RequestBody AccountUpdateRequest request){
        sysAccountService.saveEntity(request);
        return Result.success();
    }
}
